<?php

class Calculator extends Model
{
  // public fields
  public $expression;
  public $HasResult;
  
  public $result;
  
  public $soapClient;
  public $soapException;
    
  public function __construct(){
    $this->HasResult = false;
  }

  public function Process(){
    if( empty($this->expression))
        return;
    
    try
    {
        $args = array('value'=>"{$this->expression}");
        $this->result = $this->client()->__call('Calculation', array('parameters' =>  $args));
        if( $this->result )
            $this->result = $this->result->CalculationResult;
            
    }
    catch(Exception $e)
    {
        $this->soapException = $e;
        return ($this->HasResult = false);
    }
    
    return ($this->HasResult = true);
  }
  
  public function client(){
    
    if( !isset($this->soapClient) ){
            
        $wsdl = System::ConfigManager()->WebService['wsdl'];
        $options = System::ConfigManager()->WebService['options'];
        
        $this->soapClient = new SoapClient($wsdl, $options);
    }
    
    return $this->soapClient;
  }
  public function getResult(){
    return $this->result;
  }
  
  public function getWarning(){
    return "";
  }
  
   
}
